import os
import sys
from typing import Optional

import PySide6.QtCore
import PySide6.QtWidgets
import PySide6.QtGui
from PySide6.QtCore import Qt

sys.path.append('..')
from MainWindow.MWBase import MWBase
from PSData.PSData import PSData
from Widget.ItemWidget.WDataUpdateList import WDataUpdateList
from Widget.MdiArea.WDropableMdi import WDropableMdi

from .DataBulider import DataBulider


class MainWindow(MWBase):
    def __init__(self, parent: Optional[PySide6.QtWidgets.QWidget] = None, flags: PySide6.QtCore.Qt.WindowFlags = Qt.Widget) -> None:
        super().__init__(parent=parent, flags=flags)
        self.PsServerEnable(0x0001, 0x01)
        self._ui.centralwidget.layout().addWidget(WDropableMdi(self))
        data_ = PSData('GetWidgetList')
        print(self.PsGetDataFromSync(0x0002, 0x01, data_).value)
        data_builder_ = DataBulider()
        data_builder_.StartBuilderData()
        self.PsServerEnable(0x0001, 0x01)

    def closeEvent(self, event: PySide6.QtGui.QCloseEvent) -> None:
        super().closeEvent(event)
        self.PsDisableAllService()

